#Demo5.ps1
.\InitializeLG4N.ps1 

function TestLevel{
 Write-host "Level $($Log.Logger.Level)" -for green
 $Log.Debug("Level Debug.")
 $Log.Info("Level Info.")
 $Log.Warn("Level Warn.")
 $Log.Error("Level Error.")
 $Log.Fatal("Level Fatal.")
}
Cls
 #config d'origine
Copy "$Pwd\PSLogColor0.App.Config" "$Pwd\PSLogColor.App.Config"
 
 #Charge une configuration XML
Set-LogXMLConfigurator "$Pwd\PSLogColor.App.Config"
$Log = [log4net.LogManager]::GetLogger("LogPowerShell")
TestLevel
Pause
 
 #Charge une configuration XML en mode surveillance.
Set-LogXMLConfigurator "$Pwd\PSLogColor.App.Config" -Watch
 #On modifie le contenu du fichier surveill?
[xml] $xml=get-content "$PWD\PSLogColor.App.Config"
$Root = $xml.log4net.appender                                                                                     
#  # Ajoute le noeud Mapping suivant
#  <log4net>
#   <appender name="AppenderPSLogConsole" type="log4net.Appender.ColoredConsoleAppender">
#     ...
#     <mapping>
#         <level value="FATAL" />
#         <foreColor value="Red" />
#         <backColor value="Red, HighIntensity" />
#     </mapping>                                                                                                                   
$Mapping= $xml.CreateElement("mapping")                                                                     
[void]$Root.AppendChild($Mapping)                                                                                  
                                                                                                                  
 $ElementLevel = $xml.CreateElement("level")
  $Attribut = $xml.CreateAttribute("value")
  $Attribut.psbase.Value = "FATAL"
  [void]$ElementLevel.SetAttributeNode($Attribut)                                                                        
 [void]$Mapping.AppendChild($ElementLevel)                                                                                  
                                                                                                                  
 $FColor = $xml.CreateElement("forecolor")                                                                           
  $Attribut = $xml.CreateAttribute("value")
  $Attribut.psbase.Value = "Red"
  [void]$FColor.SetAttributeNode($Attribut)                                                                        
 [void]$Mapping.AppendChild($FColor)
 
 $BColor = $xml.CreateElement("backcolor")                                                                           
  $Attribut = $xml.CreateAttribute("value")
  $Attribut.psbase.Value = "Red, HighIntensity"
  [void]$BColor.SetAttributeNode($Attribut)                                                                        
 [void]$Mapping.AppendChild($BColor) 
$xml.Save("$Pwd\PSLogColor.App.Config")
 #Le mapping des couleurs est pris en compte automatiquement
Sleep 1
TestLevel
Pause

Stop-Log



